<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col :span="24" :xs="24">
        <!-- 数据筛选表单 -->
        <el-form
          ref="queryForm"
          :model="queryParams"
          :inline="true"
          label-width="100px"
        >
          <!-- 数据筛选表单组件 -->
          <el-form-item label="入住订单编号" prop="checkinNo">
            <el-input
              v-model="queryParams.checkinNo"
              placeholder="请输入入住订单编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="房间ID" prop="roomId">
            <el-input
              v-model="queryParams.roomId"
              placeholder="请输入房间ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="客户ID" prop="customerId">
            <el-input
              v-model="queryParams.customerId"
              placeholder="请输入客户ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="预住天数" prop="reserveDay">
            <el-input
              v-model="queryParams.reserveDay"
              placeholder="请输入预住天数"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="入住时间" prop="checkinTime">
            <el-input
              v-model="queryParams.checkinTime"
              placeholder="请输入入住时间"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="预计退房时间" prop="reserveTimeLeave">
            <el-input
              v-model="queryParams.reserveTimeLeave"
              placeholder="请输入预计退房时间"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="押金" prop="deposit">
            <el-input
              v-model="queryParams.deposit"
              placeholder="请输入押金"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="房费" prop="checkinPrice">
            <el-input
              v-model="queryParams.checkinPrice"
              placeholder="请输入房费"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="应付总金额" prop="totalMoney">
            <el-input
              v-model="queryParams.totalMoney"
              placeholder="请输入应付总金额"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="收到金额" prop="payMoney">
            <el-input
              v-model="queryParams.payMoney"
              placeholder="请输入收到金额"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="订单状态" prop="checkinStatus">
            <el-input
              v-model="queryParams.checkinStatus"
              placeholder="请输入订单状态"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="渠道ID" prop="wayDiscountId">
            <el-input
              v-model="queryParams.wayDiscountId"
              placeholder="请输入渠道ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="节假日ID" prop="dateDiscountId">
            <el-input
              v-model="queryParams.dateDiscountId"
              placeholder="请输入节假日ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <!-- 数据筛选操作按钮 -->
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置
            </el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="3">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="small"
              @click="handleAdd"
              >新增hotelCheckin
            </el-button>
          </el-col>
        </el-row>

        <!-- 数据表格 -->
        <el-table v-loading="loading" :data="hotelCheckinList">
          <!-- 数据表格列 -->
          <el-table-column label="入住明细ID" align="center" prop="checkinId" />
          <el-table-column
            label="入住订单编号"
            align="center"
            prop="checkinNo"
          />
          <el-table-column label="房间ID" align="center" prop="roomId" />
          <el-table-column label="客户ID" align="center" prop="customerId" />
          <el-table-column label="预住天数" align="center" prop="reserveDay" />
          <el-table-column label="入住时间" align="center" prop="checkinTime">
            <!-- <template slot-scope="scope">
              {{ scope.row.checkinTime | timeFormat }}
            </template> -->
          </el-table-column>
          <el-table-column
            label="预计退房时间"
            align="center"
            prop="reserveTimeLeave"
          />
          <el-table-column label="押金" align="center" prop="deposit" />
          <el-table-column label="房费" align="center" prop="checkinPrice" />
          <el-table-column
            label="应付总金额"
            align="center"
            prop="totalMoney"
          />
          <el-table-column label="收到金额" align="center" prop="payMoney" />
          <el-table-column
            label="订单状态"
            align="center"
            prop="checkinStatus"
          />
          <el-table-column label="渠道ID" align="center" prop="wayDiscountId" />
          <el-table-column
            label="节假日ID"
            align="center"
            prop="dateDiscountId"
          />
          <!-- 数据行操作按钮 -->
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="small"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                >修改
              </el-button>
              <el-button
                size="small"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 数据分页加载 -->
        <el-pagination
          :current-page="pageNum"
          :page-sizes="[5, 10, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 添加修改hotelCheckin对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!-- 数据编辑表单组件 -->
        <el-form-item label="入住订单编号" prop="checkinNo">
          <el-input v-model="form.checkinNo" placeholder="请输入入住订单编号" />
        </el-form-item>
        <el-form-item label="房间ID" prop="roomId">
          <el-input v-model="form.roomId" placeholder="请输入房间ID" />
        </el-form-item>
        <el-form-item label="客户ID" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入客户ID" />
        </el-form-item>
        <el-form-item label="预住天数" prop="reserveDay">
          <el-input v-model="form.reserveDay" placeholder="请输入预住天数" />
        </el-form-item>
        <el-form-item label="入住时间" prop="checkinTime">
          <el-input v-model="form.checkinTime" placeholder="请输入入住时间" />
        </el-form-item>
        <el-form-item label="预计退房时间" prop="reserveTimeLeave">
          <el-input
            v-model="form.reserveTimeLeave"
            placeholder="请输入预计退房时间"
          />
        </el-form-item>
        <el-form-item label="押金" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入押金" />
        </el-form-item>
        <el-form-item label="房费" prop="checkinPrice">
          <el-input v-model="form.checkinPrice" placeholder="请输入房费" />
        </el-form-item>
        <el-form-item label="应付总金额" prop="totalMoney">
          <el-input v-model="form.totalMoney" placeholder="请输入应付总金额" />
        </el-form-item>
        <el-form-item label="收到金额" prop="payMoney">
          <el-input v-model="form.payMoney" placeholder="请输入收到金额" />
        </el-form-item>
        <el-form-item label="订单状态" prop="checkinStatus">
          <el-input v-model="form.checkinStatus" placeholder="请输入订单状态" />
        </el-form-item>
        <el-form-item label="渠道ID" prop="wayDiscountId">
          <el-input v-model="form.wayDiscountId" placeholder="请输入渠道ID" />
        </el-form-item>
        <el-form-item label="节假日ID" prop="dateDiscountId">
          <el-input
            v-model="form.dateDiscountId"
            placeholder="请输入节假日ID"
          />
        </el-form-item>
      </el-form>
      <!-- 数据提交操作按钮 -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listHotelCheckinByPage,
  getHotelCheckin,
  addHotelCheckin,
  updateHotelCheckin,
  deleteHotelCheckin,
} from "@/api/checkinList";
export default {
  name: "HotelCheckin",
  data() {
    return {
      // HotelCheckin类型
      typeOptions: undefined,
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 当前页
      pageNum: 0,
      // 每页数据量
      pageSize: 0,
      // HotelCheckin表格数据
      hotelCheckinList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 数据查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        checkinId: undefined,
        checkinNo: undefined,
        roomId: undefined,
        customerId: undefined,
        reserveDay: undefined,
        checkinTime: undefined,
        reserveTimeLeave: undefined,
        realTimeLeave: undefined,
        deposit: undefined,
        checkinPrice: undefined,
        totalMoney: undefined,
        payMoney: undefined,
        checkinStatus: undefined,
        wayDiscountId: undefined,
        dateDiscountId: undefined,
      },
      // 数据编辑表单
      form: {},
      // 表单数据校验规则
      rules: {
        checkinId: [
          { required: true, message: "入住明细ID不能为空", trigger: "blur" },
        ],
        checkinNo: [
          { required: true, message: "入住订单编号不能为空", trigger: "blur" },
        ],
        roomId: [
          { required: true, message: "房间ID不能为空", trigger: "blur" },
        ],
        customerId: [
          { required: true, message: "客户ID不能为空", trigger: "blur" },
        ],
        reserveDay: [
          { required: true, message: "预住天数不能为空", trigger: "blur" },
        ],
        checkinTime: [
          { required: true, message: "入住时间不能为空", trigger: "blur" },
        ],
        reserveTimeLeave: [
          { required: true, message: "预计退房时间不能为空", trigger: "blur" },
        ],
        deposit: [{ required: true, message: "押金不能为空", trigger: "blur" }],
        checkinPrice: [
          { required: true, message: "房费不能为空", trigger: "blur" },
        ],
        totalMoney: [
          { required: true, message: "应付总金额不能为空", trigger: "blur" },
        ],
        payMoney: [
          { required: true, message: "收到金额不能为空", trigger: "blur" },
        ],
        checkinStatus: [
          { required: true, message: "订单状态不能为空", trigger: "blur" },
        ],
        wayDiscountId: [
          { required: true, message: "渠道ID不能为空", trigger: "blur" },
        ],
        dateDiscountId: [
          { required: true, message: "节假日ID不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询HotelCheckin数据列表 */
    getList() {
      this.loading = true;
      listHotelCheckinByPage(this.queryParams).then((response) => {
        this.hotelCheckinList = response.data.list;
        this.total = response.data.total;
        this.pageNum = response.data.pageNum;
        this.pageSize = response.data.pageSize;
        this.loading = false;
      });
    },
    /** 处理分页 */
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },

    /** 数据编辑对话框取消按钮 */
    cancel() {
      this.open = false;
      this.resetForm();
    },

    /** 数据编辑表单清空 */
    resetForm() {
      this.form = {
        checkinId: undefined,
        checkinNo: undefined,
        roomId: undefined,
        customerId: undefined,
        reserveDay: undefined,
        checkinTime: undefined,
        reserveTimeLeave: undefined,
        realTimeLeave: undefined,
        deposit: undefined,
        checkinPrice: undefined,
        totalMoney: undefined,
        payMoney: undefined,
        checkinStatus: undefined,
        wayDiscountId: undefined,
        dateDiscountId: undefined,
      };
    },

    /** 数据筛选参数重置按钮 */
    resetQueryParams() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 5;
    },

    /** 数据筛选搜索按钮 */
    handleQuery() {
      this.resetQueryParams();
      this.getList();
      this.$message.success("查询成功");
    },

    /** 数据筛选重置按钮 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 5,
        checkinId: undefined,
        checkinNo: undefined,
        roomId: undefined,
        customerId: undefined,
        reserveDay: undefined,
        checkinTime: undefined,
        reserveTimeLeave: undefined,
        realTimeLeave: undefined,
        deposit: undefined,
        checkinPrice: undefined,
        totalMoney: undefined,
        payMoney: undefined,
        checkinStatus: undefined,
        wayDiscountId: undefined,
        dateDiscountId: undefined,
      };
      this.getList();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.resetForm();
      this.open = true;
      this.title = "添加HotelCheckin";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.resetForm();
      getHotelCheckin(row.checkinId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改HotelCheckin";
      });
    },

    /** 数据提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.title === "修改HotelCheckin") {
            updateHotelCheckin(this.form).then((response) => {
              this.open = false;
              this.title = "";
              this.getList();
              this.$message.success(response.data);
            });
          } else {
            addHotelCheckin(this.form).then((response) => {
              this.open = false;
              this.title = "";
              this.getList();
              this.$message.success(response.data);
            });
          }
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm(
        '是否确认删除名称为"' + row.hotelCheckinName + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return deleteHotelCheckin(row.checkinId);
        })
        .then(() => {
          this.getList();
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
